<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Source: urlParamGet.js</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Source: urlParamGet.js</h1>

    



    
    <section>
        <article>
            <pre class="prettyprint source linenums"><code>
/**
 * **获取url中参数，可解码URI和base-64**
 * @param {string} [paramName='all'] - 默认获取url中所有参数，也可指定获取url中某个参数
 * @returns 默认返回所有url参数，指定获取参数后则返回指定参数
 * @example
 *
 * ```js
 * url='http://localhost:8080/?name=tom&amp;age=18';
 * 
 * urlParamGet()
 * // return {name:'tom',age:'18'}
 * 
 * urlParamGet('name')
 * // return 'tom'
 * ```
 */
const urlParamGet=(paramName='all')=>{
   let DATAS=location.search.substr(1);
   
   // 判断是否使用Base64转码
   let base64regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
   // 解码Base64
   if(base64regex.test(DATAS)){
      DATAS=window.atob(DATAS);
   }
   // 解码btoa
   DATAS=decodeURIComponent(DATAS).split("&amp;");

   // 将所有参数转换为json数组
   let Arr={};
   for(let i=0; i&lt;DATAS.length; i++){
      let arrCell=DATAS[i].split("=")
      Arr[arrCell[0]]=arrCell[1];
   }

   if(paramName=='all'){
      // 默认返回所有参数
      return Arr;
   }else{
      // 获取指定参数
      for(let name in Arr){
          if(name==paramName){
             return Arr[name]
          }
      }
      // 未找到参数
      return false;
   }
}

export default urlParamGet;</code></pre>
        </article>
    </section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Global</h3><ul><li><a href="global.html#cookieAdd">cookieAdd</a></li><li><a href="global.html#cookieGet">cookieGet</a></li><li><a href="global.html#haveCNChars">haveCNChars</a></li><li><a href="global.html#haveSpace">haveSpace</a></li><li><a href="global.html#isAndroid">isAndroid</a></li><li><a href="global.html#isApple">isApple</a></li><li><a href="global.html#isEmail">isEmail</a></li><li><a href="global.html#isIdCard">isIdCard</a></li><li><a href="global.html#isMail">isMail</a></li><li><a href="global.html#isMobile">isMobile</a></li><li><a href="global.html#isPhone">isPhone</a></li><li><a href="global.html#isQQ">isQQ</a></li><li><a href="global.html#isTel">isTel</a></li><li><a href="global.html#isTest">isTest</a></li><li><a href="global.html#isURL">isURL</a></li><li><a href="global.html#isWeixin">isWeixin</a></li><li><a href="global.html#lengthRange">lengthRange</a></li><li><a href="global.html#letterBegin">letterBegin</a></li><li><a href="global.html#localStorageAdd">localStorageAdd</a></li><li><a href="global.html#localStorageGet">localStorageGet</a></li><li><a href="global.html#pureNum">pureNum</a></li><li><a href="global.html#sessionStorageAdd">sessionStorageAdd</a></li><li><a href="global.html#sessionStorageGet">sessionStorageGet</a></li><li><a href="global.html#strDelRight">strDelRight</a></li><li><a href="global.html#strJoin">strJoin</a></li><li><a href="global.html#strTrim">strTrim</a></li><li><a href="global.html#timeStamp">timeStamp</a></li><li><a href="global.html#totalPage">totalPage</a></li><li><a href="global.html#urlParamAdd">urlParamAdd</a></li><li><a href="global.html#urlParamGet">urlParamGet</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.6</a> on Mon Nov 22 2021 17:08:01 GMT+0800 (中国标准时间)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>
